<script setup lang="ts">
import { ElLoading, ElMessage } from 'element-plus'
import APIService from '~/api/service'
import { getCurrentTime } from '~/utils/index'
import { useAuth } from '~/stores/auth/index'

definePageMeta({
    showSmallSearchBox: true,
})

const { info } = storeToRefs(useAuth())

const value = shallowRef<string>('')

const messageList = ref<any[]>([])

function handleSend() {
    if (!value.value) return ElMessage.error('信息为空')
    const loading = ElLoading.service({ lock: true })
    APIService.setCustomer(value.value).then(() => {
        messageList.value.push({
            name: info.value.username,
            time: getCurrentTime(),
            message: value.value
        })
        value.value = ''
    }).finally(() => {
        loading.close()
    })
}

const $router = useRouter()

function handleJumpAgreement(type: string, mark: string) {
    window.open($router.resolve(`/agreement?type=${type}&mark=${mark}`).href, '_blank')
}

const column = [{
    label: '入职心安元素',
    jumpLink: '/entry'
}, {
    label: '合作伙伴',
    jumpLink: '/cooperation'
}, {
    label: '在线客服',
    jumpLink: '/service',
    active: true
}, {
    label: '帮助中心',
    jumpLink: '/help'
}, {
    label: '意见反馈',
    jumpLink: '/feedback'
}]
</script>

<template>
    <div class="service">
        <ColumnNav class="left-nav" :column="column" />
        <div class="service-content">
            <div class="title">
                心安元素客服
            </div>
            <div class="content">
                <div class="content-side-item">
                    <div class="label">心安元素-客服小心 {{ getCurrentTime() }}</div>
                    <div class="value">您好，智能机器人小心很高兴为您服务！请问有什么可以帮到您的？</div>
                </div>
                <div class="content-side-item">
                    <div class="label">心安元素-客服小心 {{ getCurrentTime() }}</div>
                    <div class="link">
                        <div class="link-title">
                            以下有您所遇到的问题吗？(请点击热点问题查看答案或者在输入框输入您的问题)
                        </div>
                        <div class="link-item" @click="handleJumpAgreement('help', 'auth_buy')">购买的产品如何获得授权</div>
                        <div class="link-item" @click="handleJumpAgreement('help', 'title')">标题填写技巧</div>
                        <div class="link-item" @click="handleJumpAgreement('help', 'breif')">描述填写技巧</div>
                        <div class="link-item" @click="handleJumpAgreement('help', 'keyword')">关键字填写技巧</div>
                    </div>
                </div>

                <div class="content-self-item" v-for="(item, index) in messageList" :key="index">
                    <div class="label">{{ item.name }} {{ item.time }}</div>
                    <div class="value">{{ item.message }}</div>
                </div>

            </div>
            <div class="send-message">
                <textarea v-model="value" placeholder="很高兴为您服务，请您描述您的问题" maxlength="180"></textarea>
                <button @click="handleSend">发 送</button>
            </div>
        </div>
        <div style="clear: both;"></div>
    </div>
</template>

<style lang="less" scoped>
.service {
    width: 1250px;
    padding: 0 20px;
    margin: 0 auto;
    margin-top: 100px;
    margin-bottom: 100px;
    font-family: 'SOURCEHANSANSCN-EXTRALIGHT';

    .left-nav {
        float: left;
        margin-right: 50px;
    }

    .service-content {
        box-sizing: border-box;
        width: 1000px;
        border: 1px solid #E52129;
        float: left;

        .content-self-item {
            .value {
                text-align: right;
                font-size: 16px;
                color: #E52129;
                margin-right: 2em;
                margin-top: 5px;
            }

            .label {
                text-align: right;
                font-size: 14px;
                color: #9FA0A2;
            }
        }

        .content-side-item {
            margin-top: 20px;
            width: 615px;

            .link {
                border: 1px solid #E52129;
                border-radius: 5px;
                padding-bottom: 50px;
                margin-top: 5px;

                .link-title {
                    border-bottom: 1px solid #E52129;
                    padding: 5px 20px;
                    font-size: 16px;
                    color: #E52129;
                }

                .link-item {
                    font-size: 16px;
                    color: #E52129;
                    padding: 5px 20px;
                    cursor: pointer;
                }

            }

            .value {
                font-size: 16px;
                color: #E52129;
                text-indent: 2em;
                margin-top: 5px;
            }

            .label {
                font-size: 14px;
                color: #9FA0A2;
            }
        }

        .content {
            height: 400px;
            padding: 0 40px;
            overflow-y: auto;
        }

        .send-message {
            border-top: 1px solid #E52129;
            height: 150px;
            display: flex;

            textarea {
                box-sizing: border-box;
                flex: 9;
                border: none;
                outline: none;
                height: 100%;
                resize: none;
                padding: 10px;
            }

            button {
                flex: 1;
                cursor: pointer;
                background-color: #E52129;
                border: none;
                color: #ffffff;
            }
        }


        .title {
            padding: 10px 15px;
            color: #ffffff;
            background-color: #E52129;
            font-family: 'SOURCEHANSANSCN-LIGHT';
        }
    }
}
</style>